<template>
    <div class="count">
        <h2>当前求和为: {{sum}}, 大数据为: {{bigSum}}</h2>
        <select v-model.number="n">
            <option value="1" selected>1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <button @click="add">加</button>
        <button @click="sub">减</button>
    </div>
</template>

<script lang="ts" setup name="Count">
import { ref, toRefs} from 'vue'
import { useCountStore } from '@/store/count'
import {storeToRefs} from 'pinia'
const countStore = useCountStore()
// const {sum} = toRefs(countStore)
const {sum, bigSum} = storeToRefs(countStore)
let n = ref(1)
function add() {
    //第一种修改方式
    // countStore.sum += n.value

    //第二种修改方式
    countStore.$patch({
        sum: countStore.sum + n.value
    })

    //第三种修改方式
    // countStore.increment(n.value)
}

function sub() {
    countStore.sum -= n.value
}
</script>

<style lang="css" scoped>
.count {
    background-color: skyblue;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px ;
}

select,button {
    margin: 0 45px;
    height: 25px;
}
</style>